package com.ruoyi.cust.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.util.IdUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cust.domain.CityUser;
import com.ruoyi.cust.service.ICityUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 微信号Controller
 *
 * @author cjq
 * @date 2024-12-06
 */
@Api("微信号")
@RestController
@RequestMapping("/city/user")
public class CityUserController extends BaseController {
    @Autowired
    private ICityUserService cityUserService;

    /**
     * 查询微信号列表
     */
    @ApiOperation("查询微信号列表")
    @PreAuthorize("@ss.hasPermi('city:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(CityUser cityUser) {
        startPage();
        List<CityUser> list = cityUserService.selectCityUserList(cityUser); return getDataTable(list);
    }

    /**
     * 导出微信号列表
     */
    @ApiOperation("导出微信号列表")
    @PreAuthorize("@ss.hasPermi('city:user:export')")
    @Log(title = "微信号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CityUser cityUser) {
        List<CityUser> list = cityUserService.selectCityUserList(cityUser); ExcelUtil<CityUser> util = new ExcelUtil<CityUser>(CityUser. class);
        util.exportExcel(response, list, "微信号数据");
    }

    /**
     * 获取微信号详细信息
     */
    @ApiOperation("获取微信号详细信息")
    @PreAuthorize("@ss.hasPermi('city:user:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId) {
        return success(cityUserService.selectCityUserByUserId(userId));
    }

    /**
     * 新增微信号
     */
    @ApiOperation("新增微信号")
    @PreAuthorize("@ss.hasPermi('city:user:add')")
    @Log(title = "微信号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CityUser cityUser) {
        cityUser.setUserId(Long.valueOf(IdUtil.getSnowflake(1, 1).nextId()));
        return toAjax(cityUserService.insertCityUser(cityUser));
    }

    /**
     * 修改微信号
     */
    @ApiOperation("修改微信号")
    @PreAuthorize("@ss.hasPermi('city:user:edit')")
    @Log(title = "微信号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CityUser cityUser) {
        return toAjax(cityUserService.updateCityUser(cityUser));
    }

    /**
     * 删除微信号
     */
    @ApiOperation("删除微信号")
    @PreAuthorize("@ss.hasPermi('city:user:remove')")
    @Log(title = "微信号", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds) {
        return toAjax(cityUserService.deleteCityUserByUserIds(userIds));
    }
}
